﻿Public Class clsLoginUser
    '>>追加＆更新UserLoginテーブル
    Public Sub insUser(EquipNo As String, UserNo As String)
        Dim szSql As String = ""
        Dim user As String = ""
        user = getUserNo(EquipNo)

        If user = "" Then
            szSql = ""
            szSql &= "INSERT INTO PER.L_UserLogin (EquipNo,UserNo,EndTime) "
            szSql &= "VALUES ( "
            szSql &= String.Format("'{0}', '{1}', '{2}'",
                                  EquipNo, UserNo, setEndTime())
            szSql &= ")"
        Else
            szSql = ""
            szSql &= String.Format("UPDATE PER.L_UserLogin
                     SET UserNo='{0}',EndTime='{1}' 
                     WHERE EquipNo ='{2}'",
                    UserNo, setEndTime(), EquipNo)
        End If
        DBacs.ExecuteUpdateSql(szSql, -1)

    End Sub
    '>>停止使用時間の計算

    '<<設備Noにより、ユーザNo.を取得する
    Public Function getUserNo(EquipNo As String) As String

        Dim szSql As String = ""
        Dim user As String = ""

        szSql &= "SELECT USERNO "
        szSql &= "FROM PER.L_UserLogin "
        szSql &= "WHERE EQUIPNO = '" & EquipNo & "' "

        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1)

        If IsNothing(dt) OrElse dt.Rows.Count <= 0 Then
            user = ""
        Else
            user = dt(0)(0)
        End If

        Return user

    End Function

    '<<設備Noにより、禁止使用時間を取得する
    Public Function getEndTime(EquipNo As String) As DateTime

        Dim szSql As String = ""
        Dim endTime As DateTime = "1900/1/1"

        szSql &= "SELECT ENDTIME "
        szSql &= "FROM PER.L_UserLogin "
        szSql &= "WHERE EQUIPNO = '" & EquipNo & "' "

        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1)

        If IsNothing(dt) OrElse dt.Rows.Count <= 0 Then
            endTime = "1900/1/1"
        Else
            endTime = dt(0)(0)
        End If

        Return endTime

    End Function



End Class
